name: Increment Version

on:
  push:
    branches:
      - main

jobs:
  increment-version:
    runs-on: ubuntu-latest

    steps:
      - name: Check out code
        uses: actions/checkout@v2

      - name: Install NVM
        run: |
          curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

      - name: Install and use Node.js from .nvmrc
        run: |
          nvm install
          nvm use
        shell: bash -i {0}

      - name: Install dependencies
        run: npm ci
        shell: bash -i {0}

      - name: Configure Git
        run: |
          git config user.name "GitHub Actions"
          git config user.email "github-actions@github.com"

      - name: Increment version
        id: increment_version
        run: |
          NEW_VERSION=$(npm version patch -m "💪 Increase Version to %s")
          echo "New version: $NEW_VERSION"
          echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
          echo "name=NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
        shell: bash -i {0}

      - name: Push changes
        run: |
          git push